package com.bbva.cbm.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ejb.cbm.operatoria.bean.ClienteBean;

/**
 * Servlet implementation class MostrarImagenServlet
 */
public class MostrarImagenServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MostrarImagenServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String tipoImagen = request.getParameter("tipoImagen");
		HttpSession session=request.getSession();
		ClienteBean cliente = (ClienteBean)session.getAttribute("datosPersona");
		ServletOutputStream outPrint = null;
		response.setContentType("image/jpg");
		outPrint = response.getOutputStream();
		if(tipoImagen!=null && tipoImagen.equals("FO")){
			outPrint.write(cliente.getFoto());
		}
		
		else if(tipoImagen!=null && tipoImagen.equals("FI")){
			//File archivo = new File("D:\\temp\\imagenes\\firma.txt");
			  //FileOutputStream fos = new FileOutputStream(archivo);
			  //fos.write(cliente.getFirma());
			  //Close the output stream
			  //fos.close();
			outPrint.write(cliente.getFirma());
		}
		outPrint.flush();
		outPrint.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
